import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Unocss from 'unocss/vite'
// https://vitejs.dev/config/
//

export default defineConfig({
  optimizeDeps: {
    include: ['@kangc/v-md-editor/lib/theme/vuepress.js'],
  },
  plugins: [
    vue(),
    Unocss({configFile:"./uno.config.ts"}),
    // dts({
    //   insertTypesEntry: true,
    //   entryRoot: "libs",
    //   // exclude: ["src/**"],
    //   // @ts-ignore
    //   outDir: "dist/dist-ui/types",
    // }),
    // visualizer({ open: true, emitFile: true, filename: "stats.html" }),
    // libInjectCss(),
  ],
  build:{
    // minify:false, // 混淆和压缩选项
    lib:{
      entry:{
        index:"./index.ts",
        // ...scanEntries(['libs/Base']),
        // ...scanEntries(['libs/Data']),
      },
      name: "ui-lowcode",
      // fileName: (format) => `index.${format}.js`,
      formats: ["es"]
    },
    rollupOptions: {
      // makeAbsoluteExternalsRelative:false,
      external: ["vue", "vue-router","pina"],
      output: {
        dir: "dist/dist-ui",
        hoistTransitiveImports:false,
        // preserveModules:true,
        // preserveModulesRoot:"libs",
        exports: "named",
        chunkFileNames: 'chunks/[name].[hash].js',
        entryFileNames:(t) => {
          return t.name == 'index' ? '[name].js' : 'libs/[name]/index.[hash].js'
        },
        // chunkFileNames: (ckinfo) => {
        //   console.log(ckinfo)
        //   return `${ckinfo.name}-${ckinfo.type}.js`
        // },
        assetFileNames:'[ext]/[name]-[hash][extname]',
        manualChunks: id => {
          // 将 node_modules 中的代码单独打包成一个 JS 文件
          if(id.indexOf('node_modules') != -1) {
            return 'vendor'
          }
        },
        // assetFileNames: (ckinfo) => {
        //   console.log(ckinfo)
        //   return 'assets/index.css'
        // },
        globals: {
          vue: "Vue",
          "vue-router": "VueRouter",
        },
      },
    },
  }
})
